package com.study.leetcode;
//https://leetcode-cn.com/problems/path-sum-iii/
public class Solution_437 {
    private int res = 0;

    public int pathSum(TreeNode root, int targetSum) {
        if(root == null) return 0;
        tryPathSum(root, targetSum);
        pathSum(root.left,targetSum);
        pathSum(root.right,targetSum);
        return res;
    }

    private void tryPathSum(TreeNode root, int tempSum) {
        if (root == null) return;
        tempSum -=root.val;
        if(tempSum==0){
            res++;
        }
        tryPathSum(root.left, tempSum);
        tryPathSum(root.right, tempSum);
    }
}
